const domainName = getApp().globalData.domainName
const header = {'content-type':'application/x-www-form-urlencoded'}
const dataType = 'json'
const method = 'POST'
const responseType = 'text'

const windowWidth = wx.getSystemInfoSync().windowWidth

// pages/view_transcript/view_transcript.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    loading:true,
    see_answer:null,
    page_no:0,
  },

  home(){
    wx.switchTab({
      url: '/pages/index/index',
    })
  },

  see_answer(e){
    this.setData({
      see_answer:e.currentTarget.id
    })
  },

  page_init(transcript_id){
    wx.request({
      url: domainName + '/view_transcript_init',
      data: {
        transcript_id,
      },
      dataType: dataType,
      enableCache: true,
      enableHttp2: true,
      enableQuic: true,
      header: header,
      method: method,
      responseType: responseType,
      timeout: 0,
      success: res => {
        // console.log('res.data',res.data)
        wx.hideLoading()
        let transcript_info = res.data.transcript_info
        this.wrong_list = res.data.wrong_list
        this.setData({
          transcript_info: transcript_info,
          ti_info:this.wrong_list[this.data.page_no],
          loading:false,
        })
        wx.setNavigationBarTitle({
          title: transcript_info.real_name + ' 的成绩单',
        })
      },
    })
  },

  next_ti(){
    let page_no = this.data.page_no + 1
    if(page_no<this.wrong_list.length){
      this.setData({
        ti_info:this.wrong_list[page_no],
        page_no:page_no,
      })
    }

  },
  pre_ti(){
    let page_no = this.data.page_no - 1
    if(page_no>=0){
      this.setData({
        ti_info:this.wrong_list[page_no],
        page_no:page_no,
      })
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log('options',options)
    this.transcript_id = options.transcript_id
    this.page_init(this.transcript_id)
  },

})